package com.selfdriving.activity;

import net.tsz.afinal.annotation.view.ViewInject;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.selfdriving.R;
import com.selfdriving.dialog.MessageDialog;

public class RegisterOneActivity extends BaseActivity implements
		android.view.View.OnClickListener
{
	@ViewInject(id = R.id.btn_setNum, click = "btn_setNum")
	Button btn_setNum;

	@ViewInject(id = R.id.et_number)
	EditText et_number;

	@ViewInject(id = R.id.tvAgreement, click = "tvAgreement")
	TextView tvAgreement;

	@ViewInject(id = R.id.btn_back, click = "btn_back")
	Button btn_back;

	@ViewInject(id = R.id.btn_ok, click = "btn_ok")
	Button btn_ok;

	private MessageDialog dialog;

	public static final String TEXT_FORMAT = "注册即表示你同意  <font size='5'><U >%s</U></font>";

	public String agreement = "用户协议";

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.register_one);
		String txtstr = String.format(TEXT_FORMAT, agreement);
		Spanned spt = Html.fromHtml(txtstr);
		tvAgreement.setText(spt);
	}

	public void btn_back(View v)
	{
		new AlertDialog.Builder(this).setTitle("提示").setMessage("确定要放弃注册？")
				.setNegativeButton("确定", new OnClickListener()
				{

					@Override
					public void onClick(DialogInterface arg0, int arg1)
					{
						RegisterOneActivity.this.finish();
					}
				}).setNeutralButton("取消", new OnClickListener()
				{

					@Override
					public void onClick(DialogInterface dialog, int which)
					{
						dialog.dismiss();
					}
				}).show();
	}

	public void btn_ok(View v)
	{
		String phone = et_number.getText().toString();
		if (phone.length() < 1)
		{
			showToast("请输入您的手机号码");
			return;
		} else if (phone.length() != 11)
		{
			showToast("请输入11位数手机号码");
			return;
		}
		// Intent intent = new Intent(this, RegisterTwoActivity.class);
		Intent intent = new Intent(this, RegisterThreeActivity.class);
		intent.putExtra("phone", phone);
		startActivity(intent);
	}

	public void tvAgreement(View v)
	{
		dialog = new MessageDialog(this, "提示", "我是用户协议", "确定", "取消", true,
				false, this);
		dialog.show();
	}

	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.dialog_generic_btn_button1:
			dialog.dismiss();
			break;

		default:
			break;
		}

	}

}
